﻿
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BuildConfiguratorNS;
using System.IO;

/// <summary>
/// This class will have the responsibilites like create the build parameter's structure 
/// and create the BuildConfigurator class and attach the  build parameter's structure to it. 
/// </summary>
public partial class _Default : System.Web.UI.Page
{
    /// <summary>
    /// Sername will capture excuting server name in order to create the link for ccnet website
    /// </summary>
    internal string SerName;
//    private IList<BuildParameters.BuildParameters> bldparams = new List<BuildParameters.BuildParameters>();

    /// <summary>
    /// BuildConfigurator.BuildConfigurator object will take the build parameter as an argument and create the ccnet config and build.proj files 
    /// </summary>
    private BuildConfiguratorNS.BuildConfigurator bc;

    /// <summary>
    /// Page Load Event will be loading the all client side events for the controls
    /// </summary>
    /// <param name="sender"> it is the object of the class</param>
    /// <param name="e"> event args of the class</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        string[] drives = Environment.GetLogicalDrives();
        string strDrives = string.Empty;
        foreach (string str in drives)
        {
            strDrives += str.ToString() + ",";
        }
        this.txtdrives.Value = strDrives.ToString();

        this.SerName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
        this.SerName = "http://" + this.SerName + "/ccnet";

        this.bc = new BuildConfiguratorNS.BuildConfigurator();

        this.txtBldTimeout.Attributes.Add("onblur", "return IsNumeric(this.value);");
        this.txtBldIntrvl.Attributes.Add("onblur", "return IsNumeric(this.value);");
        this.txtTimeOut.Attributes.Add("onblur", "return IsNumeric(this.value);");
        this.txtSlnFle.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtSlnFle.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtStylecopsettings.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtNunitRptFile.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtNunitDLLname.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtNCLog.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtFxPrjFileName.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtFxRptFile.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtSand.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtSandOutDir.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtNDprjFile.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtNDRptDir.Attributes.Add("onblur", "return IsSpecialChar(this.value);");
        this.txtfrmEmail.Attributes.Add("onblur", "return isValidEmail(this.value,true);");
        this.txtToEmail.Attributes.Add("onblur", "return SplitCommastrings(this.value);");

        this.Form.Attributes.Add("OnLoad", "Form_load();");
        this.btnApply.Attributes.Add("onClick", "return ValSumbit();");
      
        this.chkVersion.Attributes.Add("OnClick", "Ver_Changed();");
		
      

        if (ViewState["TypedPassword"] != null)
        {
            ViewState["TypedPassword"] = txtPassword.Text;
            txtPassword.Attributes.Add("value", ViewState["TypedPassword"].ToString());
        }
        else
        {
            ViewState["TypedPassword"] = txtPassword.Text;
        }

        if (!IsPostBack)
        {
            //IList<BuildParameters.BuildParameters> bLdParams = BuildConfigurator.BuildConfigurator.GetProjectBuildConfigurations();
            IList<string> bLdParams = BuildConfiguratorNS.BuildConfigurator.GetProjectBuildConfigurations();
            if (bLdParams.Count > 0)
            {
                //ApplyProjectToGui(bLdParams[0].GeneralSettings.CCnetProjectName);
                ApplyProjectToGui(bLdParams[0]);
            }
			
			
        }

        //if (buildParameters.Count > 0)
        //{
        // ApplyProjectToGui(buildParameters[0].GeneralSettings.CCnetProjectName);
        // }

        //IList<BuildParameters.BuildParameters> buildParameters = BuildConfigurator.BuildConfigurator.GetProjectBuildConfigurations();
        IList<string> buildParameters = BuildConfiguratorNS.BuildConfigurator.GetProjectBuildConfigurations();
        for (int i = 0; i < buildParameters.Count; i++)
        {
            ListItem litm = new ListItem(buildParameters[i]);

            if (!this.lstPrjName.Items.Contains(litm))
            {
                this.lstPrjName.Items.Add(buildParameters[i]);
            }
        }
		
    }

    /// <summary>
    /// this apply method will create the Build.proj and ccnet.config file in the server and start the ccnet windows service 
    /// </summary>
    /// <param name="sender">button object of the class</param>
    /// <param name="e"> args of the button object</param>
    protected void BtnApply_Click(object sender, EventArgs e)
	{
		BuildParameters bparam = new BuildParameters();
		GeneralSettings gs = new GeneralSettings();
		{
			gs.CCnetProjectName = txtPrjName.Text;
			gs.TargetPath = txtTargetPath.Text.Trim();

			if (!string.IsNullOrEmpty(txtTargetPath.Text))
			{
				if (!Directory.Exists(txtTargetPath.Text.Trim()))
				{
					DirectoryInfo di = Directory.CreateDirectory(txtTargetPath.Text.Trim());
				}
			}

		}
		gs.DevEnvPath = txtDevEnvPath.Text.Trim();
		bparam.GeneralSettings = gs;

		PreScriptSettings ps = new PreScriptSettings();
		{
			ps.EnablePreScript = chkPreBuild.Checked;
			ps.PreScriptFile = txtPreBldFile.Text;
		}

		bparam.PreScriptSettings = ps;

		VersioningSettings vs = new VersioningSettings();
		{
			vs.EnableVersion = chkVersion.Checked;
			vs.MajorVersion = txtMajor.Text;
			vs.MinorVersion = txtMinor.Text;
			vs.Build = txtBuildversion.Text;
			vs.Revision = txtRevisionversion.Text;
		}

		bparam.VersioningSettings = vs;
		SourceControlSettings scS = new SourceControlSettings();
		{
			//SVN source control assignment
			
			scS.SourceType = ddlSourceType.SelectedItem.Text;

			if (ddlSourceType.SelectedIndex == 0)
			{

				if (!string.IsNullOrEmpty(txtTrunkUri.Text))
				{
					scS.TrunkUrl = txtTrunkUri.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtUser.Text))
				{
					scS.UserName = txtUser.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtPassword.Text))
				{
					scS.Password = txtPassword.Text.Trim();
				}
				scS.AutoGetSource = chkAtGtSrc.Checked.ToString();
				scS.TagOnSuccess = chkTgBldSucs.Checked.ToString();
				if (!string.IsNullOrEmpty(txtBseURI.Text))
				{
					scS.TagBaseUrl = txtBseURI.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtTimeOut.Text))
				{
					scS.Timeout = txtTimeOut.Text.Trim();
				}
			}
			//VSTS source control assignment
			
			else if (ddlSourceType.SelectedIndex == 1)
			{
				if (!string.IsNullOrEmpty(txtServer.Text))
				{
					scS.TrunkUrl = txtServer.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtProject.Text))
				{
					scS.Vstsproject = txtProject.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtVSTSUser.Text))
				{
					scS.UserName = txtVSTSUser.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtVSTSpassword.Text))
				{
					scS.Password = txtVSTSpassword.Text.Trim();
				}
				scS.AutoGetSource = chkVSTSAtGtSrc.Checked.ToString();
				scS.TagOnSuccess = chkVSTSAppLbl.Checked.ToString();
			}
			//ClearCase source control assignment
			
			else if (ddlSourceType.SelectedIndex == 2)
			{
				if (!string.IsNullOrEmpty(txtViewPath.Text))
				{
					scS.CcViewPath = txtViewPath.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtBranch.Text))
				{
					scS.CCBranch = txtBranch.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtProjVobName.Text))
				{
					scS.CCProjectVob = txtProjVobName.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtViewName.Text))
				{
					scS.CcViewName = txtViewName.Text.Trim();
				}
				if (!string.IsNullOrEmpty(txtCcTimeout.Text))
				{
					scS.Timeout = txtCcTimeout.Text.Trim();
				}
				scS.AutoGetSource = Checkbox1.Checked.ToString();
				scS.TagOnSuccess = Checkbox2.Checked.ToString();
				scS.IsCCBaseLine = Checkbox3.Checked.ToString();
			}
		}
		bparam.SourceControlSettings = scS;

        // Build Trigger section
        
        if (ChkBldTrger.Checked)
        {
            TriggerSettings trgset = new TriggerSettings();
            if (ChkIntTrigg.Checked)
            {
                trgset.EnableTrigger = ChkIntTrigg.Checked;
                trgset.TriggerInterval = txtBldIntrvl.Text;
                trgset.BuildCondition = drpIntTrig.SelectedItem.Text;

            }
            else
            {
                trgset.EnableTrigger = ChkIntTrigg.Checked;
                trgset.TriggerInterval = string.Empty;
                trgset.BuildCondition = string.Empty;
            }
            bparam.TriggerSettings = trgset;

            FilterTriggerSetting trgFiltSet = new FilterTriggerSetting();
            if (chkFiltTrig.Checked)
            {
                trgFiltSet.EnableFilterTrigger = chkFiltTrig.Checked;
                trgFiltSet.StartTime = txtFiltStTime.Text;
                trgFiltSet.EndTime = txtFiltEndTime.Text;
                trgFiltSet.DuratinoSecs = txtFiltDuration.Text;
            }
            else
            {
                trgFiltSet.EnableFilterTrigger = chkFiltTrig.Checked;
                trgFiltSet.StartTime = string.Empty;
                trgFiltSet.EndTime = string.Empty;
                trgFiltSet.DuratinoSecs = string.Empty;
            }
            bparam.FilterTriggerSetting = trgFiltSet;

            ScheduleTriggerSetting schedTrigSet = new ScheduleTriggerSetting();
            if (chkSchedTrig.Checked)
            {
                string chkItems = string.Empty;
                schedTrigSet.EnablescheduleTrigger = chkSchedTrig.Checked;
                schedTrigSet.BuildCondition = drpSchedTrig.SelectedItem.Text;
                schedTrigSet.TriggerIntervalTime = txtSchedTrigTime.Text;
                foreach (ListItem lItem in chkListSchedTrig.Items)
                {
                    if (lItem.Selected)
                    {
                        chkItems += lItem.Text + ";";
                    }

                }
                schedTrigSet.WeekDays = chkItems;
            }
            else
            {
                string chkItems = string.Empty;
                schedTrigSet.EnablescheduleTrigger = chkSchedTrig.Checked;
                schedTrigSet.BuildCondition = string.Empty;
                schedTrigSet.TriggerIntervalTime = string.Empty;
                schedTrigSet.WeekDays = string.Empty;
            }
            bparam.ScheduleTriggerSetting = schedTrigSet;
        }
        else
        {
            //Interval trigger section
            TriggerSettings trgset = new TriggerSettings();
            trgset.EnableTrigger = false;
            trgset.BuildCondition = string.Empty;
            trgset.TriggerInterval = string.Empty;
            bparam.TriggerSettings = trgset;

            //Filter trigger section
            FilterTriggerSetting trgFiltSet = new FilterTriggerSetting();
            trgFiltSet.EnableFilterTrigger = false;
            trgFiltSet.DuratinoSecs = string.Empty;
            trgFiltSet.EndTime = string.Empty;
            trgFiltSet.StartTime = string.Empty;
            bparam.FilterTriggerSetting = trgFiltSet;

            //Schedule trigger section
            ScheduleTriggerSetting schedTrigSet = new ScheduleTriggerSetting();
            schedTrigSet.EnablescheduleTrigger = false;
            schedTrigSet.BuildCondition = string.Empty;
            schedTrigSet.TriggerIntervalTime = string.Empty;
            schedTrigSet.WeekDays = string.Empty;
            bparam.ScheduleTriggerSetting = schedTrigSet;
        }

		CompileSettings cmpilSet = new CompileSettings();
		{
			cmpilSet.BuildConfiguration = txtBldConfig.Text;
			cmpilSet.BuildTimeout = txtBldTimeout.Text;
			cmpilSet.SolutionFile = txtSlnFle.Text;
			cmpilSet.CheckinWaitingTime = this.txtWaitingTime.Text;

		}

		bparam.CompileSettings = cmpilSet;
		StyleCopSettings styleCop = new StyleCopSettings();
		{
			styleCop.EnableStyleCop = chkStyleCop.Checked;
			styleCop.StyleCopCustomSettingsFile = txtStylecopsettings.Text;
			//styleCop.StyleCopReportFile = txtStyleCopRpt.Text;
		}
		bparam.StyleCopSettings = styleCop;


		//nunit and mstest object creation and validation

		NUnitSettings nunitset;
		MstestSettings mstest;
		string strunittestDependants = string.Empty;
		string strmstestDependants = string.Empty;

		if (chkNunit.Checked == true)
		{
			if (drpTestType.SelectedIndex == 0)
			{
				nunitset = new NUnitSettings();
				{
					nunitset.EnableNUnit = true;
					if (!string.IsNullOrEmpty(txtNunitEXEPath.Text))
					{
						nunitset.NUnitEXEPath = txtNunitEXEPath.Text.Trim();
					}
					if (!string.IsNullOrEmpty(txtNunitRptFile.Text))
					{
						nunitset.NUnitReportFile = txtNunitRptFile.Text.Trim();
					}
					if (!string.IsNullOrEmpty(txtNunitDLLname.Text))
					{
						nunitset.NUnitDLLName = txtNunitDLLname.Text.Trim();
					}
				}

				for (int i = 0; i <= chklstDepntTesting.Items.Count - 1; i++)
				{
					if (chklstDepntTesting.Items[i].Selected)
					{
						strunittestDependants += chklstDepntTesting.Items[i].Text + ";";
					}
				}
				if (!string.IsNullOrEmpty(strunittestDependants))
				{
					nunitset.NUnitDependants = strunittestDependants.Substring(0, strunittestDependants.LastIndexOf(@";"));
				}

				bparam.NUnitSettings = nunitset;
				mstest = new MstestSettings();
				{
					mstest.MstestExe = string.Empty;
					mstest.MstestDll = string.Empty;
					mstest.Mstestoutput = string.Empty;
					mstest.EnableMstestTask = false;
				}

				bparam.MSTestSettings = mstest;

			}
			else if (drpTestType.SelectedIndex == 1)
			{
				mstest = new MstestSettings();
				{
					if (!string.IsNullOrEmpty(txtmstextexe.Text))
					{
						mstest.MstestExe = txtmstextexe.Text.Trim();
					}
					if (!string.IsNullOrEmpty(txtmstestdll.Text))
					{
						mstest.MstestDll = txtmstestdll.Text.Trim();
					}
					if (!string.IsNullOrEmpty(txtmstestOutput.Text))
					{
						mstest.Mstestoutput = txtmstestOutput.Text.Trim();
					}
					mstest.EnableMstestTask = true;

					for (int i = 0; i <= chklstDepntTesting.Items.Count - 1; i++)
					{
						if (chklstDepntTesting.Items[i].Selected)
						{
							strmstestDependants += chklstDepntTesting.Items[i].Text + ";";
						}
					}
					if (!string.IsNullOrEmpty(strmstestDependants))
					{
						mstest.MsTestDependants = strmstestDependants.Substring(0, strmstestDependants.LastIndexOf(@";"));
					}

					bparam.MSTestSettings = mstest;

					nunitset = new NUnitSettings();
					{
						nunitset.EnableNUnit = false;
						nunitset.NUnitEXEPath = string.Empty;
						nunitset.NUnitReportFile = string.Empty;
						nunitset.NUnitDLLName = string.Empty;

					}
					bparam.NUnitSettings = nunitset;

				}
			}
		}

		else
		{
			nunitset = new NUnitSettings();
			{
				nunitset.EnableNUnit = false;
				nunitset.NUnitEXEPath = string.Empty;
				nunitset.NUnitReportFile = string.Empty;
				nunitset.NUnitDLLName = string.Empty;

			}
			bparam.NUnitSettings = nunitset;

			{
				mstest = new MstestSettings();
				mstest.MstestExe = string.Empty;
				mstest.MstestDll = string.Empty;
				mstest.Mstestoutput = string.Empty;
				mstest.EnableMstestTask = false;
			}
			bparam.MSTestSettings = mstest;

		}

		NCoverSettings ncovr = null;
        MSCodeCoverageSettings msCover = null;
		if (chkNcover.Checked == true)
		{
			if (ddlCodeCoverage.SelectedIndex == 0)
			{
				ncovr = new NCoverSettings();
				{
					ncovr.EnableNCover = true;
					ncovr.NCoverLogFile = txtNCLog.Text;
					if (chklstDepntNCover.Items[0].Selected)
					{
						ncovr.NCoverDependants = chklstDepntNCover.Items[0].Text;
					}
				}
				bparam.NCoverSettings = ncovr;

				msCover = new MSCodeCoverageSettings();
				{
					msCover.EnableMSCodeCoverage = false;
					msCover.InstrExePath = string.Empty;
					msCover.PerfCmdExePath = string.Empty;
					msCover.MsTestExePath = string.Empty;
					msCover.InstrBinaries = string.Empty;
					msCover.TestBinary = string.Empty;
					msCover.CoverageOutputFile = string.Empty;
					msCover.MscovRepLink = string.Empty;
				}
				bparam.MSCodeCoverageSettings = msCover;
			}
			else if (ddlCodeCoverage.SelectedIndex == 1)
			{
				msCover = new MSCodeCoverageSettings();
				{
					msCover.EnableMSCodeCoverage = true;
					msCover.InstrExePath = txtInstEXEPath.Text;
					msCover.PerfCmdExePath = txtPerfCMDpath.Text;
					msCover.MsTestExePath = txtMSTestEXEpath.Text;
					msCover.InstrBinaries = txtInstBinaries.Text;
					msCover.TestBinary = txtTestBinary.Text;
					msCover.CoverageOutputFile = txtOutputCoverageFile.Text;
					msCover.MscovRepLink = txtMSCovRptLink.Text;
				}
				bparam.MSCodeCoverageSettings = msCover;

				ncovr = new NCoverSettings();
				{
					ncovr.EnableNCover = false;
					ncovr.NCoverLogFile = string.Empty;
				}
				bparam.NCoverSettings = ncovr;

			}
		}
		else
		{
			ncovr = new NCoverSettings();
			{
				ncovr.EnableNCover = false;
				ncovr.NCoverLogFile = string.Empty;
			}
			bparam.NCoverSettings = ncovr;

			msCover = new MSCodeCoverageSettings();
			{
				msCover.EnableMSCodeCoverage = false;
				msCover.InstrExePath = string.Empty;
				msCover.PerfCmdExePath = string.Empty;
				msCover.MsTestExePath = string.Empty;
				msCover.InstrBinaries = string.Empty;
				msCover.TestBinary = string.Empty;
				msCover.CoverageOutputFile = string.Empty;
			}
			bparam.MSCodeCoverageSettings = msCover;
		}

		FxCopSettings fxcp = new FxCopSettings();
		{
			if (ChkFx.Checked)
			{
				fxcp.EnableFxCop = true;
				fxcp.FxCopProjectFile = txtFxPrjFileName.Text;
				fxcp.FxCopReportFile = txtFxRptFile.Text;
				if (chklstDepntFxCop.Items[0].Selected)
				{
					fxcp.FxCopDependants = chklstDepntFxCop.Items[0].Text;
				}
			}
			else
			{
				fxcp.EnableFxCop = false;
				fxcp.FxCopProjectFile = string.Empty;
				fxcp.FxCopReportFile = string.Empty;
			}

		}

		bparam.FxCopSettings = fxcp;

		CatNetSettings catnet = new CatNetSettings();
		{
			if (chkCATNET.Checked)
			{
				catnet.EnableCatNet = true;
				catnet.ScanFiles = txtScanAssemblies.Text;
				catnet.CNPath = txtCatNetpath.Text;
				catnet.CNRptFileName = txtRptFileName.Text;
			}
			else
			{
				catnet.EnableCatNet = false;
				catnet.ScanFiles = string.Empty;
				catnet.CNPath = string.Empty;
				catnet.CNRptFileName = string.Empty;
			}
		}

		bparam.CatNetSettings = catnet;

		SandcastleHelpFileBuilderSettings sandcastleSett = new SandcastleHelpFileBuilderSettings();
		{
			string strSHFBDependants = string.Empty;
			if (ChkSand.Checked)
			{
				sandcastleSett.EnableSandcastleHelpFileBuilder = true;
				sandcastleSett.SandcastleHelpFileBuilderProjectFile = txtSand.Text;
				sandcastleSett.SandcastleHelpFileBuilderOutputDirectory = txtSandOutDir.Text;

				for (int i = 0; i <= chklstDepntSHFB.Items.Count - 1; i++)
				{
					if (chklstDepntSHFB.Items[i].Selected)
					{
						strSHFBDependants += chklstDepntSHFB.Items[i].Text + ";";
					}
				}
				if (!string.IsNullOrEmpty(strSHFBDependants))
				{
					sandcastleSett.SHFBDependants = strSHFBDependants.Substring(0, strSHFBDependants.LastIndexOf(@";"));
				}

			}
			else
			{
				sandcastleSett.EnableSandcastleHelpFileBuilder = false;
				sandcastleSett.SandcastleHelpFileBuilderProjectFile = string.Empty;
				sandcastleSett.SandcastleHelpFileBuilderOutputDirectory = string.Empty;
			}

		}

		bparam.SandcastleHelpFileBuilderSettings = sandcastleSett;
		NDependSettings ndependset = new NDependSettings();
		{
			if (chkND.Checked)
			{
				ndependset.EnableNDepend = true;
				ndependset.NDependProjectFile = txtNDprjFile.Text;
				ndependset.NDependReportDirectory = txtNDRptDir.Text;
				if (chklstDepntNDepend.Items[0].Selected)
				{
					ndependset.NDependDependants = chklstDepntNDepend.Items[0].Text;
				}
			}
			else
			{
				ndependset.EnableNDepend = false;
				ndependset.NDependProjectFile = string.Empty;
				ndependset.NDependReportDirectory = string.Empty;
			}
		}

		bparam.NDependSettings = ndependset;
		DatabaseSettings dbset = new DatabaseSettings();
		{
			if (chkDB.Checked)
			{
				dbset.EnableDatabase = true;
				dbset.DBServerName = txtDBServer.Text;
				dbset.DBName = txtDBName.Text;
				dbset.DBLogin = txtDBUser.Text;
				dbset.DBPassword = txtPwrd.Text;
				if (chklstDepntDB.Items[0].Selected)
				{
					dbset.DBDependants = chklstDepntDB.Items[0].Text;
				}
			}
			else
			{
				dbset.EnableDatabase = false;
				dbset.DBServerName = string.Empty;
				dbset.DBName = string.Empty;
				dbset.DBLogin = string.Empty;
				dbset.DBPassword = string.Empty;
			}
		}

		bparam.DatabaseSettings = dbset;
		EmailSettings emailSet = new EmailSettings();
		{
			emailSet.EnableEmail = chkEmail.Checked;
			emailSet.SmtpServer = txtSmtpSvr.Text;
			emailSet.FromAddresses = txtfrmEmail.Text;
			emailSet.ToAddresses = txtToEmail.Text;
			//emailSet.Subject = txtSubject.Text;
			//emailSet.Body = txtBody.Text;
		}

		bparam.EmailSettings = emailSet;
		PostScriptSettings posbld = new PostScriptSettings();
		{
			if (chkPstBld.Checked)
			{
				posbld.EnablePostScript = true;
				posbld.PostScriptFile = txtPostBld.Text.Trim();
			}
			else
			{
				posbld.EnablePostScript = false;
				posbld.PostScriptFile = String.Empty;
			}

			if (chkPstCmp.Checked)
			{
				posbld.EnablePostCompile = true;
				posbld.PostCompileScriptFile = txtPostCompile.Text.Trim();
			}
			else
			{
				posbld.EnablePostCompile = false;
				posbld.PostCompileScriptFile = String.Empty;
			}

			if (chkPstDpl.Checked)
			{
				posbld.EnablePostDeploy = true;
				posbld.PostDeployScriptFile = txtPostDeploy.Text.Trim();
			}
			else
			{
				posbld.EnablePostDeploy = false;
				posbld.PostDeployScriptFile = String.Empty;
			}

		}

		bparam.PostScriptSettings = posbld;

		IISSettings IISConfig = new IISSettings();
		{
			string strIIS = string.Empty;
			if (chkIIS.Checked)
			{
				IISConfig.EnableIIS = true;
				IISConfig.IISType = ddlIISType.SelectedItem.Text.Trim();
				IISConfig.ApplicationPoolName = txtAppPoolName.Text.Trim();
				IISConfig.PhysicalDirectoryPath = txtPhysicalLocation.Text.Trim();
				IISConfig.VirtualDirectoryName = txtAliasName.Text.Trim();
				IISConfig.WebProjectPath = txtWebProject.Value.ToString();
				IISConfig.WebServerName = txtWebServerName.Text.Trim();
				IISConfig.ProductionServerLocation = txtProdServLoc.Text.Trim();
				IISConfig.QAServerLocation = txtQAServLoc.Text.Trim();
				IISConfig.DevelopmentServerLocation = txtDevServLoc.Text.Trim();
				for (int i = 0; i <= chklstDepntIIS.Items.Count - 1; i++)
				{
					if (chklstDepntIIS.Items[i].Selected)
					{
						strIIS += chklstDepntIIS.Items[i].Text + ";";
					}
				}
				if (!string.IsNullOrEmpty(strIIS))
				{
					IISConfig.IISDependants = strIIS.Substring(0, strIIS.LastIndexOf(@";"));
				}

			}
			else
			{
				IISConfig.EnableIIS = false;
				IISConfig.IISType = string.Empty;
				IISConfig.ApplicationPoolName = string.Empty;
				IISConfig.PhysicalDirectoryPath = string.Empty;
				IISConfig.VirtualDirectoryName = string.Empty;
				IISConfig.WebProjectPath = "";
				IISConfig.WebServerName = string.Empty;
			}
		}

		bparam.IISSettings = IISConfig;

		try
		{

			BuildConfigurator.ApplyBuildConfiguration(bparam);
			GetApplyProjectList();

		}
		catch (Exception ex)
		{
			Response.Write(ex.Message);
		}
	}

    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        BuildConfiguratorNS.BuildConfigurator.DeleteBuildConfiguration(txtPrjName.Text);
        GetApplyProjectList();
    }

    protected void ApplyProjectToGui(string projectName)
    {
        BuildParameters bldParam = BuildConfiguratorNS.BuildConfigurator.GetProjectBuildConfiguration(projectName);
        this.txtPrjName.Text = bldParam.GeneralSettings.CCnetProjectName;
        this.txtTargetPath.Text = bldParam.GeneralSettings.TargetPath;
        this.txtBldTimeout.Text = bldParam.CompileSettings.BuildTimeout;
        this.txtBldConfig.Text = bldParam.CompileSettings.BuildConfiguration;
        this.txtSlnFle.Text = bldParam.CompileSettings.SolutionFile;
        this.txtWaitingTime.Text = bldParam.CompileSettings.CheckinWaitingTime;
		this.txtDevEnvPath.Text = bldParam.GeneralSettings.DevEnvPath; 

        this.chkVersion.Checked = bldParam.VersioningSettings.EnableVersion;
        this.txtMajor.Text = bldParam.VersioningSettings.MajorVersion;
        this.txtMinor.Text = bldParam.VersioningSettings.MinorVersion;
        this.txtBuildversion.Text = bldParam.VersioningSettings.Build;
        this.txtRevisionversion.Text = bldParam.VersioningSettings.Revision;
        if (bldParam.SourceControlSettings != null)
        {
            if (!string.IsNullOrEmpty(bldParam.SourceControlSettings.SourceType))
            {
                if (bldParam.SourceControlSettings.SourceType == "svn")
                {
                    this.ddlSourceType.SelectedIndex = 0;
                    tblVSTS.Visible = Convert.ToBoolean("false");
                    tblClearCase.Visible = Convert.ToBoolean("false");
                    tblSVN.Visible = Convert.ToBoolean("true");
                }
                else if (bldParam.SourceControlSettings.SourceType == "vsts")
                {
                    this.ddlSourceType.SelectedIndex = 1;
                    tblVSTS.Visible = Convert.ToBoolean("true");
                    tblSVN.Visible = Convert.ToBoolean("false");
                    tblClearCase.Visible = Convert.ToBoolean("false");
                }
                else if (bldParam.SourceControlSettings.SourceType == "clearcase")
                {
                    this.ddlSourceType.SelectedIndex = 2;
                    tblVSTS.Visible = Convert.ToBoolean("false");
                    tblSVN.Visible = Convert.ToBoolean("false");
                    tblClearCase.Visible = Convert.ToBoolean("true");
                }
                this.ddlSourceType.SelectedItem.Text = bldParam.SourceControlSettings.SourceType;
            }
            
            switch (bldParam.SourceControlSettings.SourceType)
            {
                case "svn":
                    this.txtTrunkUri.Text = bldParam.SourceControlSettings.TrunkUrl;
                    this.txtUser.Text = bldParam.SourceControlSettings.UserName;
                    this.txtPassword.Text = bldParam.SourceControlSettings.Password;
                    this.txtTimeOut.Text = bldParam.SourceControlSettings.Timeout;
                    if (bldParam.SourceControlSettings.AutoGetSource == "true")
                    {
                        this.chkAtGtSrc.Checked = true;
                    }
                    else
                    {
                        this.chkAtGtSrc.Checked = false;
                    }

                    if (bldParam.SourceControlSettings.TagOnSuccess == "true")
                    {
                        this.chkTgBldSucs.Checked = true;
                    }
                    else
                    {
                        this.chkTgBldSucs.Checked = false;
                    }
                    this.txtBseURI.Text = bldParam.SourceControlSettings.TagBaseUrl;
                    break;
                case "vsts":
                    this.txtServer.Text = bldParam.SourceControlSettings.TrunkUrl;
                    this.txtVSTSUser.Text = bldParam.SourceControlSettings.UserName;
                    this.txtVSTSpassword.Text = bldParam.SourceControlSettings.Password;
                    if (bldParam.SourceControlSettings.AutoGetSource == "true")
                    {
                        this.chkVSTSAtGtSrc.Checked = true;
                    }
                    else
                    {
                        this.chkVSTSAtGtSrc.Checked = false;
                    }

                    if (bldParam.SourceControlSettings.TagOnSuccess == "true")
                    {
                        this.chkVSTSAppLbl.Checked = true;
                    }
                    else
                    {
                        this.chkVSTSAppLbl.Checked = false;
                    }
                    this.txtProject.Text = bldParam.SourceControlSettings.Vstsproject;
                    break;
                case "clearcase":
                    txtViewPath.Text = bldParam.SourceControlSettings.CcViewPath;
                    txtBranch.Text = bldParam.SourceControlSettings.CCBranch;
                    txtProjVobName.Text = bldParam.SourceControlSettings.CCProjectVob;
                    txtViewName.Text = bldParam.SourceControlSettings.CcViewName;
                    txtCcTimeout.Text = bldParam.SourceControlSettings.Timeout;
                    if (bldParam.SourceControlSettings.AutoGetSource == "true")
                    {
                        Checkbox1.Checked = true;
                    }
                    else
                    {
                        Checkbox1.Checked = false;
                    }
                    if (bldParam.SourceControlSettings.TagOnSuccess == "true")
                    {
                        Checkbox2.Checked = true;
                    }
                    else
                    {
                        Checkbox2.Checked = false;
                    }
                    if (bldParam.SourceControlSettings.IsCCBaseLine == "true")
                    {
                        Checkbox3.Checked = true;
                    }
                    else
                    {
                        Checkbox3.Checked = false;
                    }

                    break;

                default:
                    break;

            }
        }

        this.chkPreBuild.Checked = bldParam.PreScriptSettings.EnablePreScript;
        this.txtPreBldFile.Text = bldParam.PreScriptSettings.PreScriptFile;

        //Build Trigger section
        
        //Interval trigger section
        ChkBldTrger.Checked = false;
        if (bldParam.TriggerSettings.EnableTrigger == true)
        {
            ChkBldTrger.Checked = true;
            ChkIntTrigg.Checked = true;
            txtBldIntrvl.Text = bldParam.TriggerSettings.TriggerInterval;
            if (bldParam.TriggerSettings.BuildCondition == drpIntTrig.Items[0].Text)
            {
                drpIntTrig.SelectedIndex = 0;
            }
            else if (bldParam.TriggerSettings.BuildCondition == drpIntTrig.Items[1].Text)
            {
                drpIntTrig.SelectedIndex = 1;
            }
        }
        else if (bldParam.TriggerSettings.EnableTrigger == false)
        {
            ChkIntTrigg.Checked = false;
            ChkBldTrger.Checked = false;
            txtBldIntrvl.Text = string.Empty;
            if (bldParam.TriggerSettings.BuildCondition == string.Empty)
            {
                drpIntTrig.SelectedIndex = 0;
            }
        }

        //Filter trigger section
        if (bldParam.FilterTriggerSetting.EnableFilterTrigger == true)
        {
            ChkBldTrger.Checked = true;
            chkFiltTrig.Checked = true;
            txtFiltStTime.Text = bldParam.FilterTriggerSetting.StartTime;
            txtFiltEndTime.Text = bldParam.FilterTriggerSetting.EndTime;
            txtFiltDuration.Text = bldParam.FilterTriggerSetting.DuratinoSecs; 
        }
        else if (bldParam.FilterTriggerSetting.EnableFilterTrigger == false)
        {
            if (!ChkBldTrger.Checked)
            {
                ChkBldTrger.Checked = false; 
            }
            chkFiltTrig.Checked = false;
            txtFiltStTime.Text = string.Empty;
            txtFiltEndTime.Text = string.Empty;
            txtFiltDuration.Text = string.Empty;
        }

        //Schedule trigger section
        if (bldParam.ScheduleTriggerSetting.EnablescheduleTrigger == true)
        {
            //ChkBldTrger.Checked = true;
            chkSchedTrig.Checked = true;
            txtSchedTrigTime.Text = bldParam.ScheduleTriggerSetting.TriggerIntervalTime;
            if (bldParam.ScheduleTriggerSetting.BuildCondition == drpSchedTrig.Items[0].Text)
            {
                drpSchedTrig.SelectedIndex = 0;
                

            }
            else if (bldParam.ScheduleTriggerSetting.BuildCondition == drpSchedTrig.Items[1].Text)
            {
                drpSchedTrig.SelectedIndex = 1;
            }
            if (!string.IsNullOrEmpty(bldParam.ScheduleTriggerSetting.WeekDays))
            {
                string[] strArr = bldParam.ScheduleTriggerSetting.WeekDays.Split(';');
                foreach (string weekDay in strArr)
                {
                    if (weekDay == "Monday")
                    {
                        chkListSchedTrig.Items[0].Selected = true;
                    }
                    else if (weekDay == "Tuesday")
                    {
                        chkListSchedTrig.Items[1].Selected = true;
                    }
                    else if (weekDay == "Wednesday")
                    {
                        chkListSchedTrig.Items[2].Selected = true;
                    }
                    else if (weekDay == "Thursday")
                    {
                        chkListSchedTrig.Items[3].Selected = true;
                    }
                    else if (weekDay == "Friday")
                    {
                        chkListSchedTrig.Items[4].Selected = true;
                    }
                    else if (weekDay == "Saturday")
                    {
                        chkListSchedTrig.Items[5].Selected = true;
                    }
                    else if (weekDay == "Sunday")
                    {
                        chkListSchedTrig.Items[6].Selected = true;
                    }
                }
            }
        }
        else if (bldParam.ScheduleTriggerSetting.EnablescheduleTrigger == false)
        {
            if (!ChkBldTrger.Checked)
            {
                ChkBldTrger.Checked = false;
            }
            chkSchedTrig.Checked = false;
            txtSchedTrigTime.Text = string.Empty;
            if (bldParam.ScheduleTriggerSetting.BuildCondition == string.Empty)
            {
                drpSchedTrig.SelectedIndex = 0;
            }
            foreach (ListItem lItem in chkListSchedTrig.Items)
            {
                lItem.Selected = false;
            }
        }

        if (bldParam.TriggerSettings.EnableTrigger == true || bldParam.FilterTriggerSetting.EnableFilterTrigger == true || bldParam.ScheduleTriggerSetting.EnablescheduleTrigger == true)
        {
            ChkBldTrger.Checked = true;
        }

        //this.ChkBldTrger.Checked = bldParam.TriggerSettings.EnableTrigger;
        //this.txtBldIntrvl.Text = bldParam.TriggerSettings.TriggerInterval;

        this.chkStyleCop.Checked = bldParam.StyleCopSettings.EnableStyleCop;
        this.txtStylecopsettings.Text = bldParam.StyleCopSettings.StyleCopCustomSettingsFile;
        //this.txtStyleCopRpt.Text = bldParam.StyleCopSettings.StyleCopReportFile;


        if (bldParam.NUnitSettings.EnableNUnit == true)
        {
            drpTestType.SelectedIndex = 0;
            tblMSTest.Visible = false;
            tblNunit.Visible = true;
            this.chkNunit.Checked = true;

            if (!string.IsNullOrEmpty(bldParam.NUnitSettings.NUnitEXEPath))
            {
                this.txtNunitEXEPath.Text = bldParam.NUnitSettings.NUnitEXEPath;
            }
            if (!string.IsNullOrEmpty(bldParam.NUnitSettings.NUnitReportFile))
            {
                this.txtNunitRptFile.Text = bldParam.NUnitSettings.NUnitReportFile;
            }
            if (!string.IsNullOrEmpty(bldParam.NUnitSettings.NUnitDLLName))
            {
                this.txtNunitDLLname.Text = bldParam.NUnitSettings.NUnitDLLName;
            }

        }
        else if (bldParam.MSTestSettings.EnableMstestTask == true)
        {
            drpTestType.SelectedIndex = 1;
            tblMSTest.Visible = true;
            tblNunit.Visible = false;
            this.chkNunit.Checked = true;
            if (!string.IsNullOrEmpty(bldParam.MSTestSettings.MstestExe))
            {
                this.txtmstextexe.Text = bldParam.MSTestSettings.MstestExe;
            }
            if (!string.IsNullOrEmpty(bldParam.MSTestSettings.MstestDll))
            {
                this.txtmstestdll.Text = bldParam.MSTestSettings.MstestDll;
            }
            if (!string.IsNullOrEmpty(bldParam.MSTestSettings.Mstestoutput))
            {
                this.txtmstestOutput.Text = bldParam.MSTestSettings.Mstestoutput;
            }
            if (!string.IsNullOrEmpty(bldParam.MSTestSettings.MsTestDependants))
            {
                string[] strDependant = bldParam.MSTestSettings.MsTestDependants.Split(';');
                foreach (string str in strDependant)
                {
                    if (str == chklstDepntTesting.Items[0].Text)
                    {
                        chklstDepntTesting.Items[0].Selected = true;
                    }
                    else if (str == chklstDepntTesting.Items[1].Text)
                    {
                        chklstDepntTesting.Items[1].Selected = true;
                    }
                    else if (str == chklstDepntTesting.Items[2].Text)
                    {
                        chklstDepntTesting.Items[2].Selected = true;
                    }
                }
            }
        }

        else
        {
            this.chkNunit.Checked = false;
            this.txtNunitEXEPath.Text = string.Empty;
            this.txtNunitRptFile.Text = string.Empty;
            this.txtNunitDLLname.Text = string.Empty;
            this.txtmstextexe.Text = string.Empty;
            this.txtmstestdll.Text = string.Empty;
            this.txtmstestOutput.Text = string.Empty;
        }

		if (bldParam.NCoverSettings.EnableNCover == true)
		{
			ddlCodeCoverage.SelectedIndex = 0;
			tblNCover.Visible = true;
			tblMSCover.Visible = false;
			this.chkNcover.Checked = bldParam.NCoverSettings.EnableNCover;
			//this.txtNCReport.Text = bldParam.NCoverSettings.NCoverReportFile;
			this.txtNCLog.Text = bldParam.NCoverSettings.NCoverLogFile;
			if (!string.IsNullOrEmpty(bldParam.NCoverSettings.NCoverDependants))
			{
				chklstDepntNCover.Items[0].Selected = true;
			}
		}
		else if (bldParam.MSCodeCoverageSettings.EnableMSCodeCoverage == true)
		{
			ddlCodeCoverage.SelectedIndex = 1;
			tblMSCover.Visible = true;
			tblNCover.Visible = false;
			this.chkNcover.Checked = true;
			txtInstEXEPath.Text = bldParam.MSCodeCoverageSettings.InstrExePath;
			txtPerfCMDpath.Text = bldParam.MSCodeCoverageSettings.PerfCmdExePath;
			txtMSTestEXEpath.Text = bldParam.MSCodeCoverageSettings.MsTestExePath;
			txtInstBinaries.Text = bldParam.MSCodeCoverageSettings.InstrBinaries;
			txtTestBinary.Text = bldParam.MSCodeCoverageSettings.TestBinary;
			txtOutputCoverageFile.Text = bldParam.MSCodeCoverageSettings.CoverageOutputFile;
            txtMSCovRptLink.Text = bldParam.MSCodeCoverageSettings.MscovRepLink;
		}
        


        this.ChkFx.Checked = bldParam.FxCopSettings.EnableFxCop;
        this.txtFxPrjFileName.Text = bldParam.FxCopSettings.FxCopProjectFile;
        this.txtFxRptFile.Text = bldParam.FxCopSettings.FxCopReportFile;
        if (!string.IsNullOrEmpty(bldParam.FxCopSettings.FxCopDependants))
        {
            chklstDepntFxCop.Items[0].Selected = true;
        }

		if (bldParam.CatNetSettings != null)
		{
			this.chkCATNET.Checked = bldParam.CatNetSettings.EnableCatNet;
			this.txtScanAssemblies.Text = bldParam.CatNetSettings.ScanFiles;
			this.txtCatNetpath.Text = bldParam.CatNetSettings.CNPath;
			this.txtRptFileName.Text = bldParam.CatNetSettings.CNRptFileName;
		}

        this.ChkSand.Checked = bldParam.SandcastleHelpFileBuilderSettings.EnableSandcastleHelpFileBuilder;
        this.txtSand.Text = bldParam.SandcastleHelpFileBuilderSettings.SandcastleHelpFileBuilderProjectFile;
        this.txtSandOutDir.Text = bldParam.SandcastleHelpFileBuilderSettings.SandcastleHelpFileBuilderOutputDirectory;
        if (!string.IsNullOrEmpty(bldParam.SandcastleHelpFileBuilderSettings.SHFBDependants))
        {
            string[] strDependant = bldParam.SandcastleHelpFileBuilderSettings.SHFBDependants.Split(';');
            foreach (string str in strDependant)
            {
                if (str == chklstDepntSHFB.Items[0].Text)
                {
                    chklstDepntSHFB.Items[0].Selected = true;
                }
                else if (str == chklstDepntSHFB.Items[1].Text)
                {
                    chklstDepntSHFB.Items[1].Selected = true;
                }
                else if (str == chklstDepntSHFB.Items[2].Text)
                {
                    chklstDepntSHFB.Items[2].Selected = true;
                }
            }
        }

        this.chkND.Checked = bldParam.NDependSettings.EnableNDepend;
        this.txtNDprjFile.Text = bldParam.NDependSettings.NDependProjectFile;
        this.txtNDRptDir.Text = bldParam.NDependSettings.NDependReportDirectory;
        if (!string.IsNullOrEmpty(bldParam.NDependSettings.NDependDependants))
        {
            chklstDepntNDepend.Items[0].Selected = true;
        }

        this.chkDB.Checked = bldParam.DatabaseSettings.EnableDatabase;
        this.txtDBServer.Text = bldParam.DatabaseSettings.DBServerName;
        this.txtDBUser.Text = bldParam.DatabaseSettings.DBLogin;
        this.txtPwrd.Text = bldParam.DatabaseSettings.DBPassword;
        this.txtDBName.Text = bldParam.DatabaseSettings.DBName;
        if (!string.IsNullOrEmpty(bldParam.DatabaseSettings.DBDependants))
        {
            chklstDepntDB.Items[0].Selected = true;
        }

        this.chkEmail.Checked = bldParam.EmailSettings.EnableEmail;
        this.txtSmtpSvr.Text = bldParam.EmailSettings.SmtpServer;
        this.txtfrmEmail.Text = bldParam.EmailSettings.FromAddresses;
        this.txtToEmail.Text = bldParam.EmailSettings.ToAddresses;
        //this.txtSubject.Text = bldParam.EmailSettings.Subject;
        //this.txtBody.Text = bldParam.EmailSettings.Body;


        this.chkPstBld.Checked = bldParam.PostScriptSettings.EnablePostScript;
        if (!string.IsNullOrEmpty(bldParam.PostScriptSettings.PostScriptFile))
        {
            this.txtPostBld.Text = bldParam.PostScriptSettings.PostScriptFile;
        }
        this.chkPstCmp.Checked = bldParam.PostScriptSettings.EnablePostCompile;
        if (!string.IsNullOrEmpty(bldParam.PostScriptSettings.PostCompileScriptFile))
        {
            this.txtPostCompile.Text = bldParam.PostScriptSettings.PostCompileScriptFile;
        }
        this.chkPstDpl.Checked = bldParam.PostScriptSettings.EnablePostDeploy;
        if (!string.IsNullOrEmpty(bldParam.PostScriptSettings.PostDeployScriptFile))
        {
            this.txtPostDeploy.Text = bldParam.PostScriptSettings.PostDeployScriptFile;
        }

        try
        {
            this.chkIIS.Checked = bldParam.IISSettings.EnableIIS;
            this.txtAppPoolName.Text = bldParam.IISSettings.ApplicationPoolName;
            if (!string.IsNullOrEmpty(bldParam.IISSettings.IISType))
            {
                if (bldParam.IISSettings.IISType == "IIS 6.0")
                {
                    this.ddlIISType.SelectedIndex = 0;
                }
                else if (bldParam.IISSettings.IISType == "IIS 7.0")
                {
                    this.ddlIISType.SelectedIndex = 1;
                }
                //this.ddlIISType.SelectedItem.Text = bldParam.IISSettings.IISType;
            }
            this.txtPhysicalLocation.Text = bldParam.IISSettings.PhysicalDirectoryPath;
            this.txtAliasName.Text = bldParam.IISSettings.VirtualDirectoryName;
            this.txtWebProject.Value = bldParam.IISSettings.WebProjectPath;
            this.txtWebServerName.Text = bldParam.IISSettings.WebServerName;
            this.txtProdServLoc.Text = bldParam.IISSettings.ProductionServerLocation;
            this.txtQAServLoc.Text = bldParam.IISSettings.QAServerLocation;
            this.txtDevServLoc.Text = bldParam.IISSettings.DevelopmentServerLocation;
            if (!string.IsNullOrEmpty(bldParam.IISSettings.IISDependants))
            {
                string[] strarrIIS = bldParam.IISSettings.IISDependants.Split(';');
                foreach (string str in strarrIIS)
                {
                    if (str == chklstDepntIIS.Items[0].Text)
                    {
                        chklstDepntIIS.Items[0].Selected = true;
                    }
                    else if (str == chklstDepntIIS.Items[1].Text)
                    {
                        chklstDepntIIS.Items[1].Selected = true;
                    }
                    else if (str == chklstDepntIIS.Items[2].Text)
                    {
                        chklstDepntIIS.Items[2].Selected = true;
                    }
                }

            }
        }
        catch (Exception ex)
        {

        }

    }
    protected void lstPrjName_SelectedIndexChanged(object sender, EventArgs e)
    {
        ApplyProjectToGui(this.lstPrjName.SelectedItem.ToString());
    }

    protected void GetApplyProjectList()
    {

        //IList<BuildParameters.BuildParameters> buildParameters = BuildConfigurator.BuildConfigurator.GetProjectBuildConfigurations();
        IList<string> buildParameters = BuildConfiguratorNS.BuildConfigurator.GetProjectBuildConfigurations();
        this.lstPrjName.Items.Clear();

        for (int i = 0; i < buildParameters.Count; i++)
        {
            ListItem litm = new ListItem(buildParameters[i]);

            if (!this.lstPrjName.Items.Contains(litm))
            {
                this.lstPrjName.Items.Add(buildParameters[i]);
            }
        }
		//ResetFormControlValues(this.Form);
    }
    protected void ddlSourceType_SelectedIndexChanged(object sender, EventArgs e)
    {
        int ddlValue = Convert.ToInt16(ddlSourceType.SelectedItem.Value);
        switch (ddlValue)
        {
            case 0:
                tblSVN.Visible = Convert.ToBoolean("true");
                tblVSTS.Visible = Convert.ToBoolean("false");
                tblClearCase.Visible = Convert.ToBoolean("false");
                break;
            case 1:
                tblVSTS.Visible = Convert.ToBoolean("true");
                tblSVN.Visible = Convert.ToBoolean("false");
                tblClearCase.Visible = Convert.ToBoolean("false");
                break;
            case 2:
                tblClearCase.Visible = Convert.ToBoolean("true");
                tblVSTS.Visible = Convert.ToBoolean("false");
                tblSVN.Visible = Convert.ToBoolean("false");
                break;
            default:
                break;

        }
    }
    /// <summary>
    /// default buttoin will apply the default settings to the ccnet config file
    /// </summary>
    /// <param name="sender"> default button object of the class </param>
    /// <param name="e"> event args of the default button </param>

    protected void btndefault_Click(object sender, EventArgs e)
    {
        //ResetFormControlValues(this);
        this.bc.ApplyDefaultConfiguration();
        GetApplyProjectList();
    }

    private void ResetFormControlValues(Control parent)
    {
        foreach (Control c in parent.Controls)
        {
            if (c.Controls.Count > 0)
            {
                ResetFormControlValues(c);
            }
            else
            {
                switch (c.GetType().ToString())
                {
                    case "System.Web.UI.WebControls.TextBox":
                        ((TextBox)c).Text = "";
                        break;
                    case "System.Web.UI.WebControls.CheckBox":
                        ((CheckBox)c).Checked = false;
                        break;
                    case "System.Web.UI.WebControls.RadioButton":
                        ((RadioButton)c).Checked = false;
                        break;
                }
            }
        }
    }

    protected void drpTestType_SelectedIndexChanged(object sender, EventArgs e)
    {
        int val = Convert.ToInt16(drpTestType.SelectedItem.Value);
        switch (val)
        {
            case 0:
                tblNunit.Visible = true;
                tblMSTest.Visible = false;
                break;
            case 1:
                tblNunit.Visible = false;
                tblMSTest.Visible = true;
                break;
            default:
                break;
        }
    }
    

	
	
	protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
	{
		int ddlVal = Int32.Parse(ddlCodeCoverage.SelectedItem.Value);
		switch (ddlVal)
		{
			case 0:
				tblNCover.Visible = true;
				tblMSCover.Visible = false;
				break;
			case 1:
				tblMSCover.Visible = true;
				tblNCover.Visible = false;
				break;
			default:
				break;
		}
	}
	

    
}

